﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Collections.Specialized;
using System.Collections.Generic;

namespace aucn.web
{
    public partial class FAQ : System.Web.UI.Page
    {
        XmlDocument xdoc;
        XmlNamespaceManager xm;
        protected void Page_Load(object sender, EventArgs e)
        {
            xdoc = new XmlDocument();
            xdoc.Load(Server.MapPath("~/App_Data/faq.xml"));

            xm = new XmlNamespaceManager(xdoc.NameTable);
            xm.AddNamespace("ab", "http://tempuri.org/faq.xsd");

            

            this.Master.Attributes["submenu"] = "Faq";
            if (Request.QueryString["id"] != null)
            {
                Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);
            }
            this.BindData();
        }

        void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            KeyValuePair<string, string> t = (KeyValuePair<string, string>)e.Item.DataItem;
            if(t.Key == Request.QueryString["id"])
            {
                ((Panel)e.Item.FindControl("Panel1")).Visible = true;
                Literal l = (Literal)e.Item.FindControl("Literal1");

                XmlNode n = xdoc.DocumentElement.SelectSingleNode("ab:faqitem[@id='" + Request.QueryString["id"] + "']", xm);


                l.Text = n.ChildNodes[1].InnerText;
                
            }
        }

        protected void BindData()
        {
            XmlNodeList nl = xdoc.SelectNodes("//ab:faqitem", xm);

            //List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
            Dictionary<string, string> list = new Dictionary<string,string>();
            foreach (XmlNode n in nl)
            {
                list.Add(n.Attributes["id"].Value, n.FirstChild.InnerText);
            }

            Repeater1.DataSource = list;
            Repeater1.DataBind();
        }

    }
}

